//
//  functions.m
//  QQ
//
//  Created by nhope on 2017/4/17.
//  Copyright © 2017年 xiaopin. All rights reserved.
//

#import "functions.h"

/**
 检测给定的字符串是否为QQ账号(先清空首尾字符串空白字符然后进行校验)
 
 @param qq 待检测的字符串
 @return YES:合法的QQ号 NO:不是QQ号
 */
BOOL isQQ(NSString *qq)
{
    if (nil == qq || 0 == qq.length)
    {
        return NO;
    }
    NSString *qqString = [qq stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", @"^\\d{5,12}$"];
    return [predicate evaluateWithObject:qqString];
}

/**
 RGB颜色
 
 @param r Red色值
 @param g Green色值
 @param b Blue色值
 @return 对应的颜色
 */
NSColor* rgbColor(CGFloat r, CGFloat g, CGFloat b)
{
    return [NSColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0];
}

/**
 随机字符串
 
 @param length 字符串长度
 @return 返回规定长度的随机字符串
 */
NSString* randomString(int length)
{
    NSString *characters = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    NSMutableString *value = [NSMutableString string];
    for (int i=0; i<length; i++)
    {
        int index = arc4random_uniform((unsigned int)characters.length);
        NSString *character = [characters substringWithRange:NSMakeRange(index, 1)];
        [value appendString:character];
    }
    return [NSString stringWithString:value];
}



/// 登录成功的通知
NSString * const kLoginSuccessNotification  =   @"kLoginSuccessNotification";

